import { requestClient } from '#/api/request';

export function AddObj(obj: any) {
  return requestClient.post('/iam/system/role', obj);
}

export function DelObj(id: string) {
  return requestClient.delete(`/iam/system/role/${id}`);
}

export function UpdateObj(data: any) {
  return requestClient.put(`/iam/system/role/${data.id}`, data);
}

export function GetList(query: any) {
  return requestClient.post(`/iam/system/role/page`, {
    page: { current: query.current, size: query.size },
    model: {
      name: query?.name,
      status: query?.status,
      dataScope: query?.dataScope,
    },
  });
}

export function GetResourceList(query: any) {
  return requestClient.post(`/iam/system/menu/page`, {
    page: { current: query.current, size: query.size },
    model: {
      type: query?.type,
      parentId: query?.parentId,
    },
  });
}

export function getUserByRoleId(roleId: string) {
  return requestClient.get(`/iam/system/role/${roleId}/users`);
}
export function getRolePermissions(roleId: string) {
  return requestClient.get(`/iam/system/role/${roleId}/permissions`);
}
export function assignUser(obj: any) {
  return requestClient.put(`/iam/system/role/${obj.roleId}/assign-users`, obj);
}

export function assignResource(obj: any) {
  return requestClient.put(
    `/iam/system/role/${obj.roleId}/assign-resources`,
    obj,
  );
}
